from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from meiduo_admin.serializers.specs import SPUSpecificationSerializer, SPUSerializer
from meiduo_admin.utils import PageNum

from goods.models import SPUSpecification, SPU


class SpecsView(ModelViewSet):
    """
    商品规格表的增删改查
    """
    # 指定查询集
    queryset = SPUSpecification.objects.all()
    # 指定序列化器
    serializer_class = SPUSpecificationSerializer
    # 指定分页器
    pagination_class = PageNum
    permission_classes = [IsAdminUser]

    def simple(self,request):
        # 1.查询SPU表获取所有SPU表数据
        spus=SPU.objects.all()
        # 2.序列化返回SPU数据
        ser=SPUSerializer(spus,many=True)
        return Response(ser.data)
